#!/bin/bash
# Copyright (c) 2024 Kaihong (Shenzhen) Co., Ltd. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e
product_out_dir="$1"
CROOT=$(pwd)
SOURCE_ROOT=$CROOT
cd $SOURCE_ROOT

OUTPUT_SRC_DIR=$SOURCE_ROOT/output/
OUTPUT_DST_DIR=$1

OHOS_LIBS_DIR=$SOURCE_ROOT/ohos/libs/
rm $OHOS_LIBS_DIR -rf
rm -rf $OUTPUT_SRC_DIR
mkdir -p $OHOS_LIBS_DIR
find $OUTPUT_DST_DIR/libs/ -name '*.a' -exec cp "{}" $OHOS_LIBS_DIR  \;

# record modify as patch for hi3863 sdk
# hi3863_sdk.patch

./build.py -c $2 -j16
 
# fi
# after build #
if [ ! -d $OUTPUT_DST_DIR ]; then
   mkdir $OUTPUT_DST_DIR
fi
cp $OUTPUT_SRC_DIR/$3/fwpkg/$2/* $OUTPUT_DST_DIR/ -rf
